package railRoad.web.tags;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;

import railRoad.Route;
import railRoad.Schedule;

public class RouteTicketTag extends TagSupport {

	static final long serialVersionUID = 1L;

	private Integer id_route = null;
	
	public Integer getId_route() {
		return id_route;
	}
	
	public void setId_route(Integer id_route) {
		this.id_route = id_route;
	}

	@Override
	public int doStartTag() throws JspException {

		if (id_route != null) {
		try {
			Schedule schedule = Schedule.getInstance();	
			
			Route route = schedule.getRouteById(id_route.intValue());
			
			pageContext.getOut().print(route.getAvailableTicket());
			} catch (Exception ex) {
				throw new JspTagException("SimpleTag: " + ex.getMessage());
			}
			return SKIP_BODY;
		}

		return super.doStartTag();
	}

	@Override
	public int doEndTag() {
		return EVAL_PAGE;
	}
}
